﻿<MGridstack Items="@_items"
            ItemKey="item => item.ToString()"
            Margin="6"
            ItemClass="surface-container-highest d-flex align-center justify-center rounded"
            TItem="int"
            ItemOptions="ItemSize"
            DisableOneColumnMode
            SizeToContent
            ResizeHandle="GridstackResizeHandle.All">
    <ItemContent>
        @if (context == 1)
        {
            <div>@("No h: " + text)</div>
        }
        else if (context == 2)
        {
            <div>@("h=2")</div>
        }
        else if (context == 3)
        {
            <div>@("sizeToContent=false:  " + text)</div>
        }
        else if (context == 4)
        {
            <div>@("sizeToContent=3: " + text + text + text)</div>
        }
    </ItemContent>
</MGridstack>

@code {

    private string text = "some very large content that will normally not fit in the window.";

    private readonly List<int> _items = Enumerable.Range(1, 4).ToList();

    static GridstackWidget ItemSize(int item)
    {
        return item switch
        {
            1 => new() { X = 0, Y = 0, W = 2 },
            2 => new() { X = 2, Y = 0, W = 1, H = 2 },
            3 => new() { X = 3, Y = 0, W = 2, SizeToContent = false },
            4 => new() { X = 3, Y = 1, W = 2, SizeToContent = 3 },
            _ => throw new ArgumentOutOfRangeException(nameof(item), item, null)
        };
    }

}